<?php
namespace app\admin\controller;

use think\Controller;
use think\Db;
use think\Session;
use think\Request;
use think\Loader;
class Jobp extends Rbac
{
//    就业部php开发
    public function jobp()
    {
    	$month = date('m',time());
    	$day = date('d',time());


		$select_product = Db::name('product')->where('pro_sn',2)->where('pro_finish_sn',1)->paginate(10);
		$page = $select_product->render();
		$this->assign('page', $page);
		$this -> assign('select_product',$select_product);
       return $this->fetch('jobp/jobp_board');
    }
	//薪资修改
	public function jobp_alter()
    {
		$pro_id = request()->param('pro_id');
		 $find_product = Db::name('product')->where('pro_id',$pro_id)->find();
		 $this -> assign('find_product',$find_product);
		 if(!empty($_POST)){
			 $pro_id = $_POST['pro_id'];
			 $pro_avr_money = $_POST['pro_avr_money'];
			 $data = [
				'pro_avr_money' => $pro_avr_money,
			 ];
			 $update_product = Db::name('product')->where('pro_id',$pro_id)->update($data);
			if($update_product){
				$this->success('修改成功',"admin/jobp/jobp");
			}
		 }
       return $this->fetch('jobp/jobp_alter');
    }

	
	
	
	//    学生展示
    public function student()
    {
		if(!empty($_POST)){
			$job_group_id = $_POST['job_group_id'];
				if(!empty($_POST['start']) || !empty($_POST['end'])){
					var_dump($job_group_id);
				$start = strtotime($_POST['start']);
				$end = strtotime($_POST['end']);
				$select_job = Db::name('job')->where('job_group_id',$job_group_id)->where('job_getjob_time','>=',$start)->where('job_getjob_time','<=',$end)->select();
				$find_product= Db::name('product')->where('pro_id',$job_group_id)->find();

				$this->assign('select_job',$select_job);
				$this->assign('job_group_id',$job_group_id);
				$this -> assign('find_product',$find_product);
			}else{
				$this->assign('job_group_id',$job_group_id);
				$select_job = Db::name('job')->where('job_group_id',$job_group_id)->select();
				$find_product= Db::name('product')->where('pro_id',$job_group_id)->find();
				
				$this -> assign('select_job',$select_job);
				$this -> assign('find_product',$find_product);
			}
			
				
				
				
		}else{
			$job_group_id = Request()->param('job_group_id');
			$this->assign('job_group_id',$job_group_id);
			$select_job = Db::name('job')->where('job_group_id',$job_group_id)->select();
			$find_product= Db::name('product')->where('pro_id',$job_group_id)->where('pro_finish_sn',1)->find();
			
				
			
			
			$this -> assign('select_job',$select_job);
			$this -> assign('find_product',$find_product);
		}
				$last = strtotime(date('y-m-01',time()));
				$next = strtotime(date('y-m-t',time()));
				//当月就业人数
				$select_person_one = count(Db::name('job')->where('job_getjob_time','>=',$last)->where('job_getjob_time','<=',$next)->where('job_group_id',$job_group_id)->where('job_getjob_sn',2)->select());
				$this->assign('select_person_one',$select_person_one);
				//当月求职中人数
				$select_person_two = count(Db::name('job')->where('job_getjob_time','>=',$last)->where('job_getjob_time','<=',$next)->where('job_group_id',$job_group_id)->where('job_getjob_sn',3)->select());
				$this->assign('select_person_two',$select_person_two);
				//当月自主就业人数
				$select_person_three = count(Db::name('job')->where('job_getjob_time','>=',$last)->where('job_getjob_time','<=',$next)->where('job_group_id',$job_group_id)->where('job_getjob_sn',4)->select());
				$this->assign('select_person_three',$select_person_three);
       return $this->fetch('jobp/student_board');
    }
	
	//学生修改
	public function student_alter()
    {
		$job_id = request()->param('job_id');
		 $find_job = Db::name('job')->where('job_id',$job_id)->find();
		 $this -> assign('find_job',$find_job);
		 if(!empty($_POST)){
			  $job_id = $_POST['job_id'];
			 $find_job = Db::name('job')->where('job_id',$job_id)->find();
			 $job_company = !empty($_POST['job_company']) ? $_POST['job_company'] :$find_job['job_company'];
			 $job_person_money = !empty($_POST['job_person_money']) ? $_POST['job_person_money'] :$find_job['job_person_money'];
			 $job_work_name = !empty($_POST['job_work_name']) ? $_POST['job_work_name'] :$find_job['job_work_name'];
			 $job_getjob_sn = !empty($_POST['job_getjob_sn']) ? $_POST['job_getjob_sn'] : $find_job['job_getjob_sn'];
			 $job_getjob_time =  time();
			 $job_work_text = !empty($_POST['job_work_text']) ? $_POST['job_work_text'] :$find_job['job_work_text'];
			$data = [
				'job_company' => $job_company,
				'job_person_money' => $job_person_money,
				'job_work_name' => $job_work_name,
				'job_work_text' => $job_work_text,
				'job_getjob_sn' => $job_getjob_sn,
				'job_getjob_time' => $job_getjob_time,
			];
			$update_job = Db::name('job')->where('job_id',$job_id)->update($data);
			if($update_job){
				$this->success('修改成功',"admin/jobp/student?job_group_id=".$find_job['job_group_id']);
			}			
		 }
        return $this->fetch('jobp/student_alter');
    }
}
